Skip to content

feat(cli): use oxc for typescript, better reloading of stacks - #1461

Merged
BlankParticle merged 9 commits into
t3code/fix-profile-view-resizefrom
t3code/node-dev-reload
Sep 3, 2026
Merged

BlankParticle merged 9 commits into
t3code/fix-profile-view-resizefrom
t3code/node-dev-reload

Conversation

@BlankParticle

@BlankParticle BlankParticle commented Sep 2, 2026 •

Copy link
Copy Markdown
Member

Summary

Replace runtime-native watch supervisors with dependency-aware reloads owned by the exec child, and run Node TypeScript through Alchemy's Oxc loader instead of Node's strip-only support.

  • Expose the loader as @alchemy.run/node-utils/register-oxc, with TypeScript, TSX, CommonJS, tsconfig paths, emitted-extension substitution, extensionless imports, JSON imports, and inline source maps.
  • Start Node CLI children, sidecars, and Vite runners with the appropriate checkout or published loader and require a module.registerHooks-capable Node version.
  • Keep one Node exec process alive and import each stack generation under a fresh namespace.
  • Track the complete project-local dependency graph from the invocation root, including sibling infra/ and src/ trees.
  • Track Bun imports with a runtime plugin and respawn only the exec child while preserving the sidecar spawner.
  • Debounce file events and compare content fingerprints so timestamp-only and identical-content saves do not reload.
  • Log the files whose changed contents triggered each restart.
  • Deregister one-shot tsImport hooks after both successful and failed imports.

Failure handling

Plan diffs now collect their exits so a real provider or reference failure wins over sibling cancellation noise. Shared resource resolutions run in a plan-scoped detached fiber, preventing a cancelled caller from poisoning the memoized result. Dev reports internal interruption causes and waits for the next dependency change; Ctrl+C still tears down the run and prints Exited..

Stack

Depends on #1458 for the shared plan/dev terminal presentation and generation-scoped widget teardown.

@alchemy-version-bot

alchemy-version-bot Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Install the packages built from this commit:

Alchemy

alchemy

bun add https://pkg.ing/alchemy/89aa3cc

@alchemy.run/better-auth

bun add https://pkg.ing/@alchemy.run/better-auth/89aa3cc

@alchemy.run/cloudflare-runtime

bun add https://pkg.ing/@alchemy.run/cloudflare-runtime/89aa3cc

@alchemy.run/frontend-frameworks

bun add https://pkg.ing/@alchemy.run/frontend-frameworks/89aa3cc

@alchemy.run/node-utils

bun add https://pkg.ing/@alchemy.run/node-utils/89aa3cc

@alchemy.run/pr-package

bun add https://pkg.ing/@alchemy.run/pr-package/89aa3cc

@alchemy.run/floci

bun add https://pkg.ing/@alchemy.run/floci/89aa3cc

Distilled

@distilled.cloud/core

bun add https://pkg.ing/@distilled.cloud/core/cb11c5b

@distilled.cloud/aws

bun add https://pkg.ing/@distilled.cloud/aws/cb11c5b

@distilled.cloud/axiom

bun add https://pkg.ing/@distilled.cloud/axiom/cb11c5b

@distilled.cloud/cloudflare

bun add https://pkg.ing/@distilled.cloud/cloudflare/cb11c5b

@distilled.cloud/hetzner

bun add https://pkg.ing/@distilled.cloud/hetzner/cb11c5b

@distilled.cloud/neon

bun add https://pkg.ing/@distilled.cloud/neon/cb11c5b

@distilled.cloud/planetscale

bun add https://pkg.ing/@distilled.cloud/planetscale/cb11c5b

@BlankParticle
BlankParticle force-pushed the t3code/node-dev-reload branch 2 times, most recently from 4fc2133 to 945b992 Compare September 3, 2026 10:35
@BlankParticle BlankParticle changed the title feat(cli): reload Node dev stacks in process feat(cli): use oxc for typescript, better reloading of stacks Sep 3, 2026
Replace the Node tsx watch process with an Oxc-backed import loader and dependency-aware chokidar watcher. Reload changed config module graphs in process on Node while retaining Bun's existing child-process behavior.
Both runtimes now reload from the exec child's own view of the stack
graph instead of a native `--watch`, which hard-restarted the child with
no teardown (stale widget left in scrollback) and never said why.

- Log `Reloading stack: changed <files>` before every generation restart.
- Node: the change listener detaches itself on delivery; `Effect.callback`
  only runs its cleanup on interruption, so each generation was leaving a
  listener behind.
- Bun: `trackBunImports` records the project-local modules the stack
  loads through a runtime `Bun.plugin` load hook and watches them. Bun
  cannot evict evaluated modules, so a change tears the generation down
  and exits with `DEV_RELOAD_EXIT_CODE`; the `alchemy dev` supervisor
  respawns the child on that code while the sidecar spawner survives.
- node-utils: the chokidar/debounce core moves into `DependencyWatcher`,
  shared by `ImportWatcher` and the new `watch-import-bun` entry.
Node's built-in TypeScript support is strip-only (no parameter
properties, enums, or TSX) and Node 26 removed the
`--experimental-transform-types` flag that `transformTypesFlags()`
leaned on. In a checkout under Node 26 the local-provider sidecar was
spawned with no flags at all, died on the first parameter property in
alchemy's own source, and `alchemy dev` surfaced only "Interrupted."
during "Computing plan".

Every alchemy Node process now starts with alchemy's Oxc loader hooks
instead, and never relies on Node's TypeScript support:

- `bin/cli.js` gates Node on `module.registerHooks` (22.15+/23.5+/24+)
  and passes `--import` of `register-dev-mode.js` (checkout: Oxc plus
  src-condition resolution) or the new `register-oxc.js` (published).
- `register-oxc.js` transpiles only the user's own TypeScript: alchemy
  and its dependencies run their built JavaScript, and anything under
  `node_modules` is left to Node, matching Node's own rule.
- `nodeLoaderArgs(entry)` replaces `transformTypesFlags()` for the
  sidecar, the Vite dev/build runners, and the dev exec child. The
  sidecar also launches on `process.execPath` rather than PATH's `node`,
  so supervisor and sidecar never run different Node versions.
- `registerOxc()` is idempotent for the global registration, so a
  process started with `--import` can call it again safely.
Resolution now matches what tsx layers over Node for a TypeScript codebase,
for ESM and `require()` alike (Node's sync hooks serve both):

- tsconfig `paths`/`baseUrl` aliases, discovered per importing file
- `./x.js` meaning `x.ts` (source wins over an emitted sibling), plus the
  `.mjs`/`.cjs`/`.jsx` substitutions
- extensionless specifiers and directory indexes, TypeScript first
- package `exports` naming unbuilt JavaScript (checkout workspace packages)
- JSON imports without an import attribute

Candidates come from rolldown's `ResolverFactory` (tsconfig `auto`,
`extensionAlias`, `mainFiles`); Node's resolver stays the authority and
receives every candidate, so it decides formats, validates exports, and
reports the canonical errors. Bare specifiers are probed without following
symlinks so a linked workspace package still reads as a package and keeps
going through the checkout's src-condition hook.

The load hook honours Node's `module-typescript`/`commonjs-typescript`
formats; a `.ts` in a CommonJS package that uses `import` runs as ESM, as
Node's own syntax detection would. `.jsx` transpiles too. Source maps are
switched on for the process so the inline maps reach stack traces. The
register API gains `tsconfig: false`, and `tsImport()` mirrors tsx's
one-shot namespaced import.

The Bun tracker and the Node watcher scope the graph by real path, so
symlinked roots (`/tmp` on macOS, linked checkouts) match what the runtimes
report. The existing watch test no longer passes a flag Node 26 removed.
A plan whose resource references an undeployed stage reported its
`InvalidReferenceError` only some of the time; otherwise dev printed a
bare "Interrupted." and stopped. Same rate on main — `node --watch` just
left the dead process around, so it was less visible. Two causes:

- Resource diffs run concurrently and share memoized resolutions built
  with `Effect.cached`, which evaluates on the first caller's fiber. When
  that caller is cancelled, every waiter fails interrupt-only, and a
  fail-fast `Effect.all` lets that cancellation become the aggregate cause
  before the real failure arrives.
- `devKeepAlive` treated an interrupt-only cause as Ctrl+C and exited.

The plan now collects every diff's exit and reports real failures ahead
of cancellations; the per-resource resolution memo runs in a detached
fiber owned by the plan's own scope (`cachedInScope`), so a cancelled
diff cannot poison it; and the keep-alive parks on internal interruptions
too, printing the cause with a note that it is an engine/provider bug.
Ctrl+C still tears the run down: it interrupts the fiber running the
keep-alive rather than failing the effect it wraps.

Verified on a stack with the failing shape against a remote state store:
5/5 runs report the error and park (2/5 died before, on main and here).
@BlankParticle
BlankParticle merged commit 37322bb into main Sep 3, 2026
7 checks passed
@BlankParticle
BlankParticle deleted the t3code/node-dev-reload branch September 3, 2026 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant